package org.example.big_data.mapper;

import org.apache.ibatis.annotations.*;
import org.example.big_data.pojo.Category;

import java.util.List;

@Mapper
public interface CategoryMapper {

    //1. 新增文章分类
    @Insert("insert into category (category_name,category_alias,create_user,create_time,update_time) values (#{categoryName},#{categoryAlias},#{createUser},#{createTime},#{updateTime})")
    void add(Category category);

    //2. 查询所有文章分类，查询参数涉及到表中的外键create_user，这里的处理逻辑是在service层获取当代你登陆的用户id，作为外键，直接参与查询，不使用复杂的sql
    @Select("select * from category where create_user = #{userid}")
    List<Category> list(Integer userid);


    //3. 根据id查询文章分类详情,即根据id查询出一整行数据，转化为Category对象
    @Select("select * from category where id = #{id}")
    Category detail(Integer id);


    //4. 更新文章分类
    @Update("update category set category_name = #{categoryName},category_alias = #{categoryAlias},update_time = #{updateTime} where id = #{id}")
    void update(Category category);


    //5. 根据id删除文章分类
    @Delete("delete from category where id = #{id}")
    void delete(Integer id);

    
}
